﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Analizador_de_Semillas
{
    public partial class DetectarRegion : Form
    {
        static Rectangle[] detectionZone = new Rectangle[1];
        
        public DetectarRegion(Bitmap imagen)
        {
            InitializeComponent();

            this.picRegion.Image = imagen;
        }

        private void lblDefinir_Click(object sender, EventArgs e)
        {
            this.picRegion.MouseDown += new MouseEventHandler(picRegion_MouseDown);
            this.picRegion.MouseUp +=new MouseEventHandler(picRegion_MouseUp);
        }

        void  picRegion_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.X < detectionZone[0].X)
            {
                detectionZone[0].X = e.X;
            }
            else
            {
                detectionZone[0].Width = e.X - detectionZone[0].X;
            }

            if (e.Y < detectionZone[0].Y)
            {
                detectionZone[0].Y = e.Y;
            }
            else
            {
                detectionZone[0].Height = e.Y - detectionZone[0].Y;
            }

            picRegion.CreateGraphics().DrawRectangle(new Pen(Color.Red,5), detectionZone[0]);

            picRegion.Invalidate(detectionZone[0]);
        }

        void picRegion_MouseDown(object sender, MouseEventArgs e)
        {
            detectionZone[0].X = e.X;

            detectionZone[0].Y = e.Y;
        }

        private void lblFinalizar_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        public static Rectangle[] pasarZona()
        {
            return detectionZone;
        }
    }
}
